const { Sequelize } = require("sequelize");
const { isRequired } = require("../utils");

module.exports = (sequelize, DataTypes) => {
  const MapIcon = sequelize.define(
    "Icon",
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: Sequelize.UUIDV4,
        //是否允许为空
        allowNull: false,
        //是否为主键
        primaryKey: true,
        //备注
        comment: "图标id",
      },
      iconGroupId: {
        type: DataTypes.UUID,
        comment: "图标组id",
        allowNull: false,
        validate: isRequired("图标组id"),
      },
      iconUrl: {
        type: DataTypes.STRING,
        comment: "图片地址",
        allowNull: false,
        validate: isRequired("图标地址"),
      },
      width: {
        type: DataTypes.INTEGER,
        comment: "宽度",
        allowNull: false,
        validate: isRequired("宽度"),
      },
      height: {
        type: DataTypes.INTEGER,
        comment: "高度",
        allowNull: false,
        validate: isRequired("高度"),
      },
    },
    {
      timestamps: true,
      tableName: "map_icon",
      createdAt: "createTime",
      updatedAt: "updateTime",
      comment: "图标表",
    }
  );
  MapIcon.associate = function (db) {
    MapIcon.belongsTo(db.IconGroup, {
      foreignKey: "iconGroupId",
      as: "group",
    });
  };
  return MapIcon;
};
